#ifndef _SYMBOLTABLE_HPP
#define _SYMBOLTABLE_HPP

#include <string>
#include <map>
#include <vector>

constexpr int32_t GLOBAL_SCOPE = 1;
constexpr int32_t LOCAL_SCOPE  = 2;

struct Symbol {
	Symbol(const std::string& name, int index, int scope) 
		: _name(name)
		, _index(index)
		, _scope(scope) {
	}
	std::string _name;
	int _index;
	int _scope;
};


class SymbolTable {
public:
	Symbol* defineSymbol(const std::string& name, int32_t scop = GLOBAL_SCOPE) {
		Symbol* s = new Symbol(name, _definition++, GLOBAL_SCOPE);
		if (_outer != nullptr) {
			s->_scope = LOCAL_SCOPE;
		}
		_table[name] = s;
		return s;
	}

	Symbol* resolveSymbol(const std::string& name) {
		return _table[name];
	}

public:
	int _definition{ 0 };
	std::map<std::string, Symbol*> _table;
	SymbolTable* _outer{ nullptr };
};

#endif // !_SYMBOLTABLE_HPP
